<template>
  <div class="main-scroll">
    <headerc :title="title"></headerc>
    <el-card class="box-card">
      <!-- <div class="title-text">数据筛选</div> -->
      <div style="padding: 10px" class="c-filter">
        <el-form
          :inline="true"
          :model="findMsg"
          class="demo-form-inline"
          label-width="70px"
        >
          <el-form-item label="员工姓名">
            <el-input
              v-model="findMsg.emplName"
              placeholder="员工姓名"
            ></el-input>
          </el-form-item>

          <el-form-item label="所属部门">
            <el-input v-model="findMsg.dept" placeholder="所属部门"></el-input>
          </el-form-item>

          <el-form-item label="二级部门">
            <el-input
              v-model="findMsg.secondDept"
              placeholder="所属二级部门"
            ></el-input>
          </el-form-item>

          <el-form-item label="所属班组">
            <el-input v-model="findMsg.team" placeholder="所属班组"></el-input>
          </el-form-item>

          <el-form-item label="建议级别">
            <el-select
              v-model="findMsg.suggestLevel"
              placeholder="建议级别"
              @change="findLevel"
            >
              <el-option label="班组级" value="1"></el-option>
              <el-option label="车间级" value="2"></el-option>
              <el-option label="公司级" value="3"></el-option>
            </el-select>
          </el-form-item>

          <el-form-item label="提出时间">
            <el-date-picker
              v-model="findMsg.suggestDate"
              type="daterange"
              range-separator="至"
              start-placeholder="开始日期"
              end-placeholder="结束日期"
            >
            </el-date-picker>
          </el-form-item>
          <el-row>
            <el-form-item>
              <el-button type="primary" icon="el-icon-search" @click="query"
                >查询</el-button
              >
            </el-form-item>
            <el-form-item>
              <el-button type="primary" @click="reset">清除查询条件</el-button>
            </el-form-item>
          </el-row>
        </el-form>
      </div>
    </el-card>
    <el-card>
      <!-- <div class="main-seting">
        <div>
          <div class="title-text">数据列表</div> -->
          <el-button
        v-auth="'C04002'"
        style="
          float: right;
          margin-right: 20px;
          margin-bottom: 20px;
          margin-top: 20px;
        "
        icon="el-icon-download"
        @click="exportExcel"
        >导出</el-button
      >
      <el-button
        v-auth="'C04001'"
        type="primary"
        style="
          float: right;
          margin-right: 20px;
          margin-bottom: 20px;
          margin-top: 20px;
        "
        @click="dialogVisible = true"
        >添加</el-button
      >
      <div style="margin: 20px">
        <el-table
          :data="suggestList"
          border
          style="width: 100%"
          :header-cell-style="{ background: '#F6F7FB' }"
        >
          <el-table-column
            type="index"
            :index="indexAdd"
            label="序号"
            width="50"
          >
          </el-table-column>
          <el-table-column prop="dept" label="部门">
            <template slot-scope="scope">
              <p>{{ scope.row.dept }}</p>
            </template>
          </el-table-column>
          <el-table-column prop="secondDept" label="二级部门">
            <template slot-scope="scope">
              <p>{{ scope.row.secondDept }}</p>
            </template>
          </el-table-column>
          <el-table-column prop="team" label="班组">
            <template slot-scope="scope">
              <p>{{ scope.row.team }}</p>
            </template>
          </el-table-column>
          <el-table-column prop="emplName" label="姓名">
            <template slot-scope="scope">
              <p>{{ scope.row.emplName }}</p>
            </template>
          </el-table-column>
          <el-table-column prop="suggestTime" label="提出时间">
            <template slot-scope="scope">
              <p>{{ scope.row.suggestTime | formatDate('yyyy-MM-dd') }}</p>
            </template>
          </el-table-column>
          <el-table-column
            prop="content"
            :show-overflow-tooltip="true"
            label="提出建议内容"
            width="140"
          >
            <template slot-scope="scope">
              <p>{{ scope.row.content }}</p>
            </template>
          </el-table-column>
          <el-table-column prop="suggestLevel" label="建议级别">
            <template slot-scope="scope">
              <p>{{ levelfun(scope.row.suggestLevel) }}</p>
            </template>
          </el-table-column>
          <el-table-column prop="score" label="得分情况">
            <template slot-scope="scope">
              <p>{{ scope.row.score }}</p>
            </template>
          </el-table-column>
          <el-table-column
            prop="remark"
            :show-overflow-tooltip="true"
            label="备注"
          >
            <template slot-scope="scope">
              <p>{{ scope.row.remark }}</p>
            </template>
          </el-table-column>
        </el-table>
      </div>
      <el-pagination
        v-if="isUpdate"
        background
        layout="prev, pager, next"
        :page-size="pageSize"
        :total="total"
        :hide-on-single-page="total < 10"
        @current-change="currentChange"
        class="pagination"
      >
      </el-pagination>
      <!-- </div>
      </div> -->
    </el-card>
    <el-dialog title="填报须知" :visible.sync="dialogVisible" width="50%">
      <div class="notice">
        <p>一、填报要求：</p>
        <p>1、合理化建议必须具有可操作性</p>
        <p>2、语义清晰、语句简练。</p>
        <p>3、需经车间技术人员签字采纳实施后，即可加分。</p>
        <p>二、积分标准</p>
        <p>
          1、员工提合理化建议，经车间安全、设备、工艺技术员审核、实验后，记1分/条。
        </p>
        <p>2、员工所提合理化建议，被公司采纳并实施后，记2分/条。</p>
      </div>
      <span slot="footer" class="dialog-footer">
        <el-button @click="dialogVisible = false">取 消</el-button>
        <el-button
          type="primary"
          @click="
            dialogVisible = false
            dialogVisible2 = true
          "
        >
          确 定
        </el-button>
      </span>
    </el-dialog>
    <el-dialog title="添加" :visible.sync="dialogVisible2" width="35%">
      <el-form
        ref="addForm"
        :model="addForm"
        :rules="rules"
        label-width="100px"
      >
        <el-form-item label="提出时间:" prop="suggestTime">
          <el-date-picker
            style="width:300px;"
            v-model="addForm.suggestTime"
            type="date"
            value-format="yyyy-MM-dd"
            placeholder="请选择日期"
          >
          </el-date-picker>
        </el-form-item>
        <el-form-item label="建议内容:" prop="content">
          <el-input
            style="width:300px;"
            v-model="addForm.content"
            type="textarea"
            :rows="4"
            placeholder="请填写"
            maxlength="200"
            show-word-limit
          ></el-input>
        </el-form-item>
        <el-form-item label="建议级别:" prop="suggestLevel" required>
          <el-select
            style="width:300px;"
            v-model="addForm.suggestLevel"
            placeholder="请选择"
            @change="changeLevel"
          >
            <el-option label="班组级" value="1"></el-option>
            <el-option label="车间级" value="2"></el-option>
            <el-option label="公司级" value="3"></el-option>
          </el-select>
        </el-form-item>
        <el-form-item label="备注:" prop="remarks">
          <el-input
            style="width:300px;"
            v-model="addForm.remark"
            placeholder="请填写"
            type="textarea"
            :rows="4"
            maxlength="50"
            show-word-limit
          >
          </el-input>
        </el-form-item>
      </el-form>
      <span slot="footer" class="dialog-footer">
        <el-button @click="cancel">取 消</el-button>
        <el-button type="primary" @click="addSuggest">确 定</el-button>
      </span>
    </el-dialog>
  </div>
</template>

<script>
import { findUser } from '@/api/index'
import headerc from '@/components/header.vue'
import { exportMethod } from '@/utils/utils'
import { addSuggest, suggestList } from '@/api/personal-files'
export default {
  components: {
    headerc
  },
  data() {
    return {
      title: '创新与合理化建议情况',
      isUpdate: true,
      findMsg: {
        suggestStartTime: '',
        suggestEndTime: '',
        dept: '',
        emplName: '',
        secondDept: '',
        team: '',
        suggestLevel: '',
        suggestDate: ''
      },
      addForm: {
        suggestLevel: '',
        suggestTime: '',
        content: '',
        remark: ''
      },
      rules: {
        content: [
          { required: true, message: '请填写提出建议', trigger: 'blur' }
        ],
        suggestLevel: [
          { required: true, message: '请选择建议级别', trigger: 'change' }
        ],
        suggestTime: [
          { required: true, message: '请选择提出时间', trigger: 'change' }
        ]
      },
      dialogVisible: false,
      dialogVisible2: false,
      suggestList: [],
      pageNo: 1, // 分页页码
      pageSize: 10, // 每页条数
      total: 0
    }
  },
  created() {
    this.getSuggestList()
  },
  methods: {
    exportExcel() {
      const data = {
        pageNo: this.pageNo,
        pageSize: 5000,
        suggestStartTime: this.findMsg.suggestDate[0],
        suggestEndTime: this.findMsg.suggestDate[1],
        suggestLevel: this.findMsg.suggestLevel,
        dept: this.findMsg.dept,
        emplName: this.findMsg.emplName,
        secondDept: this.findMsg.secondDept,
        team: this.findMsg.team
      }
      exportMethod('suggest', data, '创新与合理化建议记录')
    },
    async getSuggestList() {
      const res = await suggestList({
        pageNo: this.pageNo,
        pageSize: this.pageSize,
        suggestStartTime: this.findMsg.suggestDate[0],
        suggestEndTime: this.findMsg.suggestDate[1],
        suggestLevel: this.findMsg.suggestLevel,
        dept: this.findMsg.dept,
        emplName: this.findMsg.emplName,
        secondDept: this.findMsg.secondDept,
        team: this.findMsg.team
      })
      if (res.code == 200) {
        this.isUpdate = true
        this.suggestList = res.data.list
        this.total = res.data.total
      }
      console.log('this.suggestList', this.suggestList)
    },
    addSuggest() {
      this.$refs.addForm.validate(async (valid) => {
        if (valid) {
          const res = await addSuggest({
            suggestTime: this.addForm.suggestTime,
            suggestLevel: this.addForm.suggestLevel,
            content: this.addForm.content,
            remark: this.addForm.remark
          })
          if (res.code == 200) {
            this.$message({
              message: '创建成功',
              type: 'success'
            })
            this.dialogVisible2 = false
            this.getSuggestList()
            this.$refs.addForm.resetFields()
            this.addForm = {
              suggestLevel: '',
              suggestLevel: '',
              suggestTime: '',
              content: '',
              remark: ''
            }
          }
          console.log('res', res)
        } else {
          return false
        }
      })
    },
    // 序号-页面切换递增
    indexAdd(index) {
      return index + 1 + (this.pageNo - 1) * this.pageSize
    },
    currentChange(pageNo) {
      this.pageNo = pageNo
      this.getSuggestList()
    },
    query() {
      this.pageNo = 1
      this.isUpdate = false
      this.getSuggestList()
    },
    reset() {
      this.findMsg.emplName = ''
      this.findMsg.dept = ''
      this.findMsg.secondDept = ''
      this.findMsg.team = ''
      this.findMsg.suggestLevel = ''
      this.findMsg.suggestDate = ''
    },
    levelfun(data) {
      if (data == 1) {
        return '班组级'
      } else if (data == 2) {
        return '车间级'
      }else if (data == 3) {
        return '公司级'
      }
    },
    findLevel(e) {
      this.findMsg.suggestLevel = e
    },
    changeLevel(e) {
      this.addForm.suggestLevel = e
    },
    cancel() {
      this.dialogVisible2 = false
      this.$refs.addForm.resetFields()
      this.addForm = {
        suggestLevel: '',
        suggestTime: '',
        content: '',
        remark: ''
      }
      // this.createForm.remark = ''
    }
  }
}
</script>

<style lang="scss" scoped>
.c-main-make {
  margin-left: 35px;
  height: 300px;
  background: #fff;
  margin-right: 35px;
  margin-bottom: 35px;
  position: relative;
  overflow: hidden;
  border: 1px #dcdee0 solid;
}
.c-main-show {
  margin-left: 35px;
  height: auto;
  background: #fff;
  margin-right: 35px;
  margin-bottom: 35px;
  position: relative;
  overflow: hidden;
  border: 1px #dcdee0 solid;
}
.title-text {
  width: 100%;
  height: 50px;
  border-bottom: 1px #dcdee0 solid;
  font-family: '微软雅黑 Bold', '微软雅黑 Regular', 微软雅黑, sans-serif;
  font-weight: 700;
  color: #666666;
  line-height: 50px;
  padding-left: 25px;
}
.main-scroll {
  height: 1000px;
  // overflow-y: scroll;
}
.pagination {
  display: flex;
  justify-content: end;
}
.box-card {
  margin-bottom: 20px;
}
.el-input {
  width: 250px;
}
.el-select {
  width: 250px;
}
</style>
